<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <el-form
          v-show="showSearch"
          ref="queryForm"
          :model="queryParams"
          :inline="true"
          label-width="100px"
        >
          <el-form-item label="志愿活动名称" prop="userName">
            <el-select
              v-model="queryParams.id"
              placeholder="商品名称"
              clearable
              size="small"
              style="width: 200px"
            >
              <el-option v-for="(item,index) in volunteerList" :key="item.id" :label="item.volunteerName" :value="item.id"/>
            </el-select>
          </el-form-item>

          <el-form-item label="用户名称" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入用户名称"
              clearable
              size="small"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >搜索
            </el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleUpdate"
            >修改</el-button>
          </el-col>

          <!-- <right-toolbar
            :show-search.sync="showSearch"
            :columns="columns"
            @queryTable="getList"
          /> -->
        </el-row>
        <el-row :gutter="10" class="mb8">
          <el-table :data="volunteerLogList" style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"/>
            <el-table-column prop="userName" label="用户账号" align="center"/>
            <el-table-column prop="nickName" label="用户名称" align="center"/>
            <el-table-column  v-if="false" prop="id" label="id" align="center" hidden/>
            <el-table-column prop="volunteerName" label="活动名称" align="center">
            </el-table-column>
            <el-table-column prop="status" label="是否到场" align="center">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.status == '0'" >未到场</el-tag>
                <el-tag v-if="scope.row.status == '1'" type="success">已到场</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间" align="center"/>
            <el-table-column
              label="操作"
              align="center"
              width="160"
              class-name="small-padding fixed-width"
            >
              <template v-if="scope.row.status != 1" slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                >修改状态</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </el-col>
    </el-row>
    <el-pagination
      :page-size.sync="queryParams.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      :page-sizes="[10, 20, 30, 40]"
      :current-page.sync="queryParams.pageNum"
      @current-change="getList"
      @size-change="getList"
    />

  </div>
</template>

<script>
import { allVolunteerList} from "@/api/volunteer/manage";
import { allVolunteerLogList, updateVolunteerLog} from "@/api/volunteer/info";
export default {
  data() {
    return {
      showSearch: true,
      queryParams:{
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        userName:undefined
      },
      queryNameParams:{
        pageNum: 1,
        pageSize: 10
      },
      volunteerList:null,
      volunteerLogList:null,
      total:null,
      title: '',
      // 是否显示弹出层
      open: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 表单参数
      form: {}
    }
  },
  methods: {
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    reset() {
      this.resetForm('form')
    },
    handleUpdate(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确定修改状态为已到场？')
        .then(function() {
          return updateVolunteerLog(ids)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('修改状态成功')
        })
        .catch(() => {})
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 添加积分 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加志愿活动'

    },
    getList() {
      this.loading = true
      allVolunteerList(this.queryNameParams).then((response) => {
        this.volunteerList = response.list
        this.total = response.total
        this.loading = false
      });
      allVolunteerLogList(this.queryParams).then((response) => {
        this.volunteerLogList = response.list
        this.total = response.total
        this.loading = false
      });
    }
  },
  created() {
    this.getList()
  },
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>


